//
//  SearchOrderViewController.m
//  HaierGMS_APP
//
//  Created by 堂堂 on 16/11/3.
//  Copyright © 2016年 堂堂. All rights reserved.
//

#import "SearchOrderViewController.h"
#import "Main2ViewController.h"
#import "IISideController.h"
#import "IIViewDeckController.h"
#import "RightViewController.h"
#import "MJRefreshNormalHeader.h"
#import "MJRefreshBackNormalFooter.h"
#import "UIColor+Hex.h"
#import "MainOrderTableViewCell.h"
#import "DropdownMenu.h"
#import "OrderDetailViewController.h"
#import "AppDelegate.h"
#import "AFHTTPRequestOperationManager.h"
#import "MBProgressHUD+MJ.h"
#import "HttpReauestParam.h"
#import "UserDefaultUtil.h"
#import "SignViewController.h"
#import "PickUpViewController.h"
#import "OppoinViewController.h"
#import <MSFSDK/MSFSDK.h>
#import "JYJViewController.h"
#import "FaildViewController.h"
#import "NoticeViewController.h"
#import "CommonDefine.h"
@interface SearchOrderViewController ()
@property NSArray *order_status;
@property NSString *http_status;
@property int size;
@property int page;
@property NSString *startDate;
@property NSString *endDate;
@property NSString *status;
@property NSString *timeStatus;

@property NSInteger hxContent;

@property NSDictionary *orderd;
@end

@implementation SearchOrderViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.search_field.delegate = self;
    self.search_field.returnKeyType = UIReturnKeySearch;
    self.order_status = @[@"201",@"401",@"301",@"901",@"501,601,610,701",@"201,401,301,901,501,601,610,701",@"201,301,401"];
    
    self.size = 20;
    self.page = 1;
    _status = self.order_status[6];
    _startDate = @"1970-01-01";
    _timeStatus = @"";
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd"];
    _endDate = [formatter stringFromDate:[NSDate date]];
    
    
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.tabview.backgroundColor = [UIColor colorWithHexString:@"#f2f2f2"];
    self.orderData = [[NSArray alloc]init];
    
    self.topview.layer.cornerRadius = 4;
    self.topview.backgroundColor = [UIColor colorWithHexString:@"#d9d9d9"];
    
    //tabView初始化
    self.tabview.delegate = self;
    self.tabview.dataSource = self;
    
    UINib *nib = [UINib nibWithNibName:@"MainOrderTableViewCell" bundle:nil];
    [self.tabview registerNib:nib forCellReuseIdentifier:@"main_order_cell"];
    
    
    if ([self.tabview respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.tabview setSeparatorInset:UIEdgeInsetsZero];
    }
    self.tabview.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    __unsafe_unretained UITableView *tableView = self.tabview;
    
    // 设置回调（一旦进入刷新状态就会调用这个refreshingBlock）
    tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        NSLog(@"刷新数据");
        
        _page = 1;
        [self getData];
        [tableView.mj_header endRefreshing];
        
    }];
    // 设置自动切换透明度(在导航栏下面自动隐藏)
    tableView.mj_header.automaticallyChangeAlpha = YES;
    tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
        NSLog(@"加载更多");
        [self getData];
        
        [tableView.mj_footer endRefreshing];
        
    }];
    // 马上进入刷新状态
    //[tableView.mj_header beginRefreshing];
    
    //头部各状态颜色
    
    self.top_color1.backgroundColor = [UIColor colorWithHexString:@"#c7003a"];
    self.top_color2.backgroundColor = [UIColor colorWithHexString:@"#5bc0de"];
    self.top_color3.backgroundColor = [UIColor colorWithHexString:@"#00d11c"];
    self.top_color4.backgroundColor = [UIColor colorWithHexString:@"#ffca00"];
    self.top_color5.backgroundColor = [UIColor colorWithHexString:@"#cccccc"];
    
    
    //下拉
    [self testData];
    
    DropdownMenu *dropdown = [[DropdownMenu alloc] initDropdownWithButtonTitles:__titleArray andLeftListArray:__leftArray andRightListArray:self._rightArray];
    dropdown.delegate = self;   //此句的代理方法可返回选中下标值
    
    dropdown.view.frame = CGRectMake(0, STATUS_AND_NAVIGATION_HEIGHT + 3, [UIScreen mainScreen].bounds.size.width / 3,  147);
   // dropdown.view.backgroundColor = [UIColor greenColor];
    [self.view addSubview:dropdown.view];
    
    //[dropdown showMenu:10001];
    
    
    
    //侧滑FilterSlideViewController
    self._slidebarVC = [[RightViewController alloc]init];
    self._slidebarVC.view.frame  = self.view.bounds;
    [self.view addSubview:self._slidebarVC.view];
    __weak typeof(self) weakSelf = self;
    self._slidebarVC.backBlock = ^(id backData){
        
        
    };
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

- (IBAction)showRightView:(id)sender {
    
    NSLog(@"showRightView");
    [self._slidebarVC showHideSidebar];
    
    __weak typeof(self) weakSelf = self;
    self._slidebarVC.backBlock = ^(id backData){
        
        NSLog(@"right回调");
        //回调
        
        NSArray * array = backData;
        weakSelf.status = array[0];
        weakSelf.startDate = array[1];
        weakSelf.endDate = array[2];
        
        weakSelf.page = 1;
        [weakSelf getData];
    };
    
}
//tab

//行数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.orderData.count;
}
//item
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    MainOrderTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"main_order_cell"];
    
    NSDictionary *dic = self.orderData[indexPath.row];
    
    //订单来源
    if([dic[@"orderFrom"] isEqualToString:@"天猫"]){
        cell.order_from_image.image = [UIImage imageNamed:@"grab_order_tm"];
    }
    if([dic[@"orderFrom"] isEqualToString:@"4PL-天猫"]){
        cell.order_from_image.image = [UIImage imageNamed:@"grab_order_tm"];
    }
    if([dic[@"orderFrom"] isEqualToString:@"其它"]){
        cell.order_from_image.image = [UIImage imageNamed:@"grab_order_qt"];
    }
    if([dic[@"orderFrom"] isEqualToString:@"极有家"]){
        cell.order_from_image.image = [UIImage imageNamed:@"grab_order_jyj"];
    }
    //订单号
    cell.order_no_text.text = dic[@"serviceNo"];
    
    //状态
    cell.order_status_text.text = [NSString stringWithFormat:@"(%@)",dic[@"serviceStatus"]];
    if ([dic[@"serviceStatus"] isEqualToString:@"待预约"]) {
        cell.order_status_text.textColor = [UIColor colorWithHexString:@"#c7003a"];
        cell.order_top_view.backgroundColor = [UIColor colorWithHexString:@"#c7003a"];
    }
    if ([dic[@"serviceStatus"] isEqualToString:@"待提货"]) {
        cell.order_status_text.textColor = [UIColor colorWithHexString:@"#5bc0de"];
        cell.order_top_view.backgroundColor = [UIColor colorWithHexString:@"#5bc0de"];
    }
    if ([dic[@"serviceStatus"] isEqualToString:@"待签收"]) {
        cell.order_status_text.textColor = [UIColor colorWithHexString:@"#00d11c"];
        cell.order_top_view.backgroundColor = [UIColor colorWithHexString:@"#00d11c"];
    }
    if ([dic[@"serviceStatus"] isEqualToString:@"问题件"]) {
        cell.order_status_text.textColor = [UIColor colorWithHexString:@"#ffca00"];
        cell.order_top_view.backgroundColor = [UIColor colorWithHexString:@"#ffca00"];
    }
    if ([dic[@"serviceStatus"] isEqualToString:@"已完成"]) {
        cell.order_status_text.textColor = [UIColor colorWithHexString:@"#cccccc"];
        cell.order_top_view.backgroundColor = [UIColor colorWithHexString:@"#cccccc"];
    }
    
    //工单日期
    NSDateFormatter *sf = [[NSDateFormatter alloc]init];
    [sf setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    
    NSDateFormatter *sf2 = [[NSDateFormatter alloc]init];
    [sf2 setDateFormat:@"yyyy-MM-dd"];
    NSDate * date = [sf dateFromString:dic[@"serviceDate"]];
    
    if(dic[@"appointmentTime"] != nil && ![dic[@"appointmentTime"] isEqualToString:@""]){
        NSDate * date2 = [sf dateFromString:dic[@"appointmentTime"]];
        if(date2.timeIntervalSince1970 - [NSDate date].timeIntervalSince1970 < 2* 60 * 60){
            [cell.order_date_text.layer setBorderWidth:1];
            [cell.order_date_text.layer setBorderColor:[UIColor colorWithHexString:@"ff7e00"].CGColor];
            cell.order_date_text.textColor = [UIColor colorWithHexString:@"ff7e00"];
            cell.order_date_text.layer.cornerRadius = 11 ;
            
            cell.order_date_text.layer.masksToBounds = YES;
        }else{
            [cell.order_date_text.layer setBorderWidth:0];
            [cell.order_date_text.layer setBorderColor:[UIColor clearColor].CGColor];
            cell.order_date_text.textColor = [UIColor blackColor];
            cell.order_date_text.layer.cornerRadius = 11 ;
            
            cell.order_date_text.layer.masksToBounds = YES;
        }
    }else{
        [cell.order_date_text.layer setBorderWidth:0];
        [cell.order_date_text.layer setBorderColor:[UIColor clearColor].CGColor];
        cell.order_date_text.textColor = [UIColor blackColor];
        cell.order_date_text.layer.cornerRadius = 11 ;
        
        cell.order_date_text.layer.masksToBounds = YES;
    }
    
    cell.order_date_text.text = [NSString stringWithFormat:@"  %@  ",[sf2 stringFromDate:date]];
    //用户
    cell.order_user_text.text = [NSString stringWithFormat:@"%@(%@)",dic[@"userName"],dic[@"userPhone"]];
    //地址1
    cell.address1_text.text = [NSString stringWithFormat:@"提货:%@",dic[@"pickupAddress"]];
    //地址2
    cell.address2_text.text = [NSString stringWithFormat:@"上门:%@",dic[@"userAddress"]];
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 120.0;
}
-(void)viewDidLayoutSubviews
{
    if ([self.tabview respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.tabview setSeparatorInset:UIEdgeInsetsMake(0,0,0,0)];
    }
    
    if ([self.tabview respondsToSelector:@selector(setLayoutMargins:)]) {
        [self.tabview setLayoutMargins:UIEdgeInsetsMake(0,0,0,0)];
    }
}
//侧滑按钮
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath

{
    
    NSLog(@"侧滑%li",(long)indexPath.row);
    
    NSString *status = @"";
    NSDictionary *dic = self.orderData[indexPath.row];
    
    _orderd = dic;
    
    if ([dic[@"serviceStatus"] isEqualToString:@"待预约"]) {
        status = @"预约";
    }
    if ([dic[@"serviceStatus"] isEqualToString:@"待提货"]) {
        status = @"提货";
    }
    if ([dic[@"serviceStatus"] isEqualToString:@"待签收"]) {
        status = @"签收";
    }
    
    if ([dic[@"serviceStatus"] isEqualToString:@"待预约"] || [dic[@"serviceStatus"] isEqualToString:@"待提货"]||[dic[@"serviceStatus"] isEqualToString:@"待签收"]) {
        UITableViewRowAction *grabRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:status handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
            NSLog(@"签收%li",(long)indexPath.row);
            
            UIStoryboard *board = [UIStoryboard storyboardWithName:@"App_Main" bundle:[NSBundle mainBundle]];
            if ([dic[@"serviceStatus"] isEqualToString:@"待预约"]) {
                OppoinViewController * vc = [board instantiateViewControllerWithIdentifier:@"appion_opp"];
                vc.serviceNo = dic[@"serviceNo"];
                vc.type = @"0";
                [self.navigationController pushViewController:vc animated:YES];
            }
            if ([dic[@"serviceStatus"] isEqualToString:@"待提货"]) {
                PickUpViewController * vc = [board instantiateViewControllerWithIdentifier:@"pick_up_opp"];
                vc.serviceNo = dic[@"serviceNo"];
                [self.navigationController pushViewController:vc animated:YES];
            }
            if ([dic[@"serviceStatus"] isEqualToString:@"待签收"]) {
                [self getOrderFrom];
            }
            
        }];
        grabRowAction.backgroundColor = [UIColor colorWithHexString:@"#ff7e00"];
        UITableViewRowAction *phoneRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"电话" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
            
            NSLog(@"电话%li",(long)indexPath.row);
            
            UIWebView*callWebview =[[UIWebView alloc] init];
            NSURL *telURL =[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",dic[@"userPhone"]]];// 貌似tel:// 或者 tel: 都行
            [callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];
            //记得添加到view上
            [self.view addSubview:callWebview];
        }];
        
        return @[phoneRowAction,grabRowAction];
    }else{
        UITableViewRowAction *detailRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"详情" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
            UIStoryboard *story = [UIStoryboard storyboardWithName:@"App_Main" bundle:[NSBundle mainBundle]];
            
            NSDictionary *dic = self.orderData[indexPath.row];
            
            OrderDetailViewController *order = [story instantiateViewControllerWithIdentifier:@"order_detail"];
            order.serviceNo = dic[@"serviceNo"];
            [self.navigationController pushViewController:order animated:YES];
            
        }];
        return @[detailRowAction];
    }
    
    return  nil;
}


-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}


//点击
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UIStoryboard *story = [UIStoryboard storyboardWithName:@"App_Main" bundle:[NSBundle mainBundle]];
    
    NSDictionary *dic = self.orderData[indexPath.row];
    
    OrderDetailViewController *order = [story instantiateViewControllerWithIdentifier:@"order_detail"];
    order.serviceNo = dic[@"serviceNo"];
    order.receiveNoType = [dic[@"receiveNoType"] integerValue];
    order.shopNoType = [dic[@"shopNoType"] integerValue];
    
    [self.navigationController pushViewController:order animated:YES];
    
    //[self presentViewController:order animated:YES completion:nil];
}
//下拉选项
//实现代理，返回选中的下标，若左边没有列表，则返回0
- (void)dropdownSelectedButtonIndex:(NSString *)index LeftIndex:(NSString *)left RightIndex:(NSString *)right {
    NSLog(@"%s : You choice button %@, left %@ and right %@", __FUNCTION__, index, left, right);
    
    if ([right isEqualToString:@"0"]) {
        _status = self.order_status[0];
    }
    if ([right isEqualToString:@"1"]) {
        _status = self.order_status[1];
    }
    if ([right isEqualToString:@"2"]) {
        _status = self.order_status[2];
    }
    if ([right isEqualToString:@"3"]) {
        _status = self.order_status[6];
    }
    
    _page = 1;
    [self getData];
    
}

//测试数据
- (void)testData {
    [self testTitleArray];
    [self testLeftArray];
    [self testRightArray];
}

//每个下拉的标题
- (void) testTitleArray {
    self._titleArray = @[@"全部"];
}

//左边列表可为空，则为单下拉菜单，可以根据需要传参
- (void)testLeftArray {
    //NSArray *One_leftArray = @[@"附近", @"熱門商區", @"香洲區", @"斗門區", @"金灣區"];
    NSArray *Two_leftArray = [[NSArray alloc] init];
    NSArray *Two_leftArray2 = [[NSArray alloc] init];
    NSArray *Two_leftArray3 = [[NSArray alloc] init];
    //    NSArray *R_leftArray = @[@"Test1", @"Test2"];
    
    
    self._leftArray = [[NSArray alloc] initWithObjects: Two_leftArray,Two_leftArray2,Two_leftArray3, nil];
}

//右边列表不可为空
- (void)testRightArray {
    NSArray *F_rightArray = @[
                              @[
                                  @{@"title":@"500米"},
                                  @{@"title":@"1000米"},
                                  @{@"title":@"2000米"},
                                  @{@"title":@"5000米"}
                                  ] ,
                              @[
                                  @{@"title":@"全部商區"},
                                  @{@"title":@"拱北"},
                                  @{@"title":@"香洲"},
                                  @{@"title":@"吉大"},
                                  @{@"title":@"華髮商都"},
                                  @{@"title":@"富華里"},
                                  @{@"title":@"揚名廣場"},
                                  @{@"title":@"摩爾廣場"},
                                  @{@"title":@"井岸鎮"},
                                  @{@"title":@"紅旗鎮"},
                                  @{@"title":@"三灶鎮"},
                                  ],
                              @[
                                  @{@"title":@"全部香洲區"},
                                  @{@"title":@"拱北"},
                                  @{@"title":@"香洲"},
                                  @{@"title":@"吉大"},
                                  @{@"title":@"華髮商都"},
                                  @{@"title":@"富華里"},
                                  @{@"title":@"揚名廣場"},
                                  @{@"title":@"摩爾廣場"},
                                  ],
                              @[
                                  @{@"title":@"全部斗門區"},
                                  @{@"title":@"井岸鎮"},
                                  ],
                              @[
                                  @{@"title":@"全部金灣區"},
                                  @{@"title":@"紅旗鎮"},
                                  @{@"title":@"三灶鎮"},
                                  ]
                              ];
    
    NSArray *S_rightArray = @[
                              @[
                                  @{@"title":@"待预约"},
                                  @{@"title":@"待提货"},
                                  @{@"title":@"待签收"},
                                  @{@"title":@"全部"},
                                  ] ,
                              @[
                                  @{@"title":@"four"}
                                  ]
                              ];
    NSArray *S_rightArray2 = @[
                               
                               ];
    NSArray *S_rightArray3 = @[
                               
                               ];
    
    self._rightArray = [[NSArray alloc] initWithObjects:S_rightArray,S_rightArray2,S_rightArray3, nil];
}
- (IBAction)showDownView:(id)sender {
    
}

-(void)viewWillAppear:(BOOL)animated{
    
    self.navigationController.navigationBar.hidden = YES;
    NSLog(@"viewWillAppear");
    _page = 1;
    [self getData];
    [super viewWillAppear:animated];
}

-(void) getData{
    
    NSString *userId =[UserDefaultUtil getUserId];
    NSDictionary * dic = @{@"identifier": userId ,@"page":[NSString stringWithFormat:@"%i",_page],@"size":[NSString stringWithFormat:@"%i",_size],@"startDate":_startDate,@"endDate":_endDate,@"query":_search_field.text,@"orderType":_timeStatus,@"status":_status};
    
    NSLog(@"%@",dic);
    
    HttpReauestParam * param = [[HttpReauestParam alloc]initWithData:@"order_list_get" content:[self dictionaryToJson:dic] urlType:0];
    AFHTTPRequestOperationManager *manage = [AFHTTPRequestOperationManager manager];
    manage.responseSerializer = [AFHTTPResponseSerializer serializer];
    // [MBProgressHUD showMessage:@"获取订单"];
    [manage POST:param.SEVICE_URL parameters:param.param success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        NSDictionary * data = [NSJSONSerialization JSONObjectWithData:operation.responseObject options:0 error:nil];
        
        
        if ([data[@"success"] boolValue]) {
            _page++;
            NSString *content = data[@"result"];
            
            NSLog(@"%@",content);
            NSArray *orderd = [NSJSONSerialization JSONObjectWithData:[content dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil];
            
            if (_page == 2) {
                self.orderData = [[NSMutableArray alloc]init];
                [self.orderData addObjectsFromArray:orderd];
            }else{
                [self.orderData addObjectsFromArray:orderd];
            }
            
            
            [self.tabview reloadData];
            
        }else{
            [MBProgressHUD showError:data[@"errorMsg"]];
        }
        [MBProgressHUD hideHUD];
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        [MBProgressHUD hideHUD];
        [MBProgressHUD showError:@"网络连接失败"];
    }];
}


-(NSString*)dictionaryToJson:(NSDictionary *)dic

{
    
    NSError *parseError = nil;
    
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:&parseError];
    
    return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    
}

- (IBAction)time_click:(id)sender {
    if ([_timeStatus isEqualToString:@"1"]) {
        _timeStatus = @"0";
        [_time_image setImage:[UIImage imageNamed:@"seearch_order_top_time_z"]];
    }else if ([_timeStatus isEqualToString:@"0"]) {
        _timeStatus = @"1";
        [_time_image setImage:[UIImage imageNamed:@"seearch_order_top_time_d"]];
    }else if ([_timeStatus isEqualToString:@""]) {
        _timeStatus = @"0";
        [_time_image setImage:[UIImage imageNamed:@"seearch_order_top_time_z"]];
    }
    
    _page = 1;
    [self getData];
}

-(void)getOrderFrom{
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:_orderd[@"serviceNo"] forKey:@"serviceNo"];
    [dic setObject:[UserDefaultUtil getUserId] forKey:@"identifier"];
    
    HttpReauestParam *param = [[HttpReauestParam alloc] initWithData:@"order_source_operator" content:[self dictionaryToJson:dic] urlType:0];
    AFHTTPRequestOperationManager *manage = [AFHTTPRequestOperationManager manager];
    manage.responseSerializer = [AFHTTPResponseSerializer serializer];
    [MBProgressHUD showMessage:@"核销验证"];
    [manage POST:param.SEVICE_URL parameters:param.param success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        NSDictionary *data = [NSJSONSerialization JSONObjectWithData:operation.responseData options:0 error:nil];
        
        NSLog(@"%@",data);
        [MBProgressHUD hideHUD];
        if([data[@"success"] boolValue]){
            NSString *content = data[@"result"];
            
            NSLog(@"%@",content);
            NSDictionary *fromData = [NSJSONSerialization JSONObjectWithData:[content dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil];
            if ([fromData[@"status"] integerValue] == 0) {
                //未核销
                if ([fromData[@"ifTms"] isEqualToString:@"1"] || [fromData[@"ifTms"] isEqualToString:@"4"] ) {
                    //天猫
                    NSDictionary *params = @{
                                             @"tpId":@"1706441746", //服务商标识
                                             @"outId":fromData[@"outerId"], //内部订单号
                                             @"orderIds":fromData[@"orderId"], //天猫父订单号，多个用逗号分隔
                                             @"serviceType": @"2"//服务类型，0：家装的送货上门并安装，1：单向安装，2：建材的送货上门，3：建材的安装，4：建材的送货上门和安装
                                             };
                    //fromData[@"serviceType"]
                    
                    
                    
                    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(callback:) name:MSFIdentifyResultNotification object:nil];
                    self.navigationController.navigationBarHidden = NO;
                    [MSFSDK callMSF:params navigationController:self.navigationController];
                    _hxContent = 0;
                }else if ([fromData[@"ifTms"] isEqualToString:@"5"] || [fromData[@"ifTms"] isEqualToString:@"6"] ) {
                    
                    //极有家
                    
                    UIStoryboard *story = [UIStoryboard storyboardWithName:@"App_Main" bundle:[NSBundle mainBundle]];
                    JYJViewController *jyjVC = [story instantiateViewControllerWithIdentifier:@"jyj_hx_view"];
                    jyjVC.serviceNo = _orderd[@"serviceNo"];
                    [self.navigationController pushViewController:jyjVC animated:YES];
                }else{
                    UIStoryboard *story = [UIStoryboard storyboardWithName:@"App_Main" bundle:[NSBundle mainBundle]];
                    SignViewController *orderSign = [story instantiateViewControllerWithIdentifier:@"sign_opp"];
                    orderSign.serviceNo = _orderd[@"serviceNo"];
                    orderSign.popCount = 2;
                    [self.navigationController pushViewController:orderSign animated:YES];
                }
            }else{
                //已核销
                UIStoryboard *story = [UIStoryboard storyboardWithName:@"App_Main" bundle:[NSBundle mainBundle]];
                SignViewController *orderSign = [story instantiateViewControllerWithIdentifier:@"sign_opp"];
                orderSign.serviceNo = _orderd[@"serviceNo"];
                orderSign.popCount = 2;
                [self.navigationController pushViewController:orderSign animated:YES];
            }
            
            
            
        }else{
            [MBProgressHUD showError:data[@"errorMsg"]];
        }
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        [MBProgressHUD hideHUD];
    }];
}
- (void)callback:(NSNotification *)notification
{
    
    NSDictionary *userInfo = notification.userInfo;
    //userInfo包括三个属性
    //signsuccess  签到是否成功，1：成功，0：不成功
    //verifysuccess 核销是否成功，1：成功，0：不成功
    //imgpath  核销图片地址， 多个图片以逗号分隔
    NSNumber *verifysuccess = [userInfo objectForKey:@"verifysuccess"];
    if ([verifysuccess boolValue]) {
        //TODO Success Operation
        NSLog(@"核销成功了");
        if (_hxContent == 0) {
            _hxContent = 1;
            [self sendHX];
        }
        
    }else if([_orderd[@"canVerification"] boolValue]){
        //核销失败
        //核销失败
        UIStoryboard *story = [UIStoryboard storyboardWithName:@"App_Main" bundle:[NSBundle mainBundle]];
        FaildViewController *faildVc= [story instantiateViewControllerWithIdentifier:@"hx_faild_view"];
        faildVc.serviceNo = _orderd[@"serviceNo"];
        [self.navigationController pushViewController:faildVc animated:YES];
    }
}

-(void)sendHX{
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:_orderd[@"serviceNo"] forKey:@"serviceNo"];
    [dic setObject:[UserDefaultUtil getUserId] forKey:@"identifier"];
    
    HttpReauestParam *param = [[HttpReauestParam alloc] initWithData:@"mao_hx_notice" content:[self dictionaryToJson:dic] urlType:0];
    AFHTTPRequestOperationManager *manage = [AFHTTPRequestOperationManager manager];
    manage.responseSerializer = [AFHTTPResponseSerializer serializer];
    [manage POST:param.SEVICE_URL parameters:param.param success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        //核销成功
        UIStoryboard *story = [UIStoryboard storyboardWithName:@"App_Main" bundle:[NSBundle mainBundle]];
        SignViewController *orderSign = [story instantiateViewControllerWithIdentifier:@"sign_opp"];
        orderSign.serviceNo = _orderd[@"serviceNo"];
        orderSign.popCount = 2;
        [self.navigationController pushViewController:orderSign animated:YES];
        
        
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        //核销成功
        UIStoryboard *story = [UIStoryboard storyboardWithName:@"App_Main" bundle:[NSBundle mainBundle]];
        SignViewController *orderSign = [story instantiateViewControllerWithIdentifier:@"sign_opp"];
        orderSign.serviceNo = _orderd[@"serviceNo"];
        orderSign.popCount = 2;
        [self.navigationController pushViewController:orderSign animated:YES];
        
        
    }];
}

- (IBAction)notice_click:(id)sender {
    
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"App_Main" bundle:[NSBundle mainBundle]];
    NoticeViewController *vc = [sb instantiateViewControllerWithIdentifier:@"notice_view"];
    [self.navigationController pushViewController:vc animated:YES];
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
   
    _page = 1;
    _status = _order_status[5];
    [self getData];
    
    if([textField isFirstResponder]){
        [textField  resignFirstResponder];
    }
    return YES;
}
- (IBAction)search_click:(id)sender {
}
- (IBAction)back_click:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}
- (IBAction)touch_view:(id)sender {
    [self.view endEditing:YES];
}
@end
